﻿package mortal.game.view.levelReward.panel
{
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import fl.controls.*;
    import fl.data.*;
    import mortal.component.window.resWin.*;
    import mortal.game.cache.*;
    import mortal.game.view.common.*;
    import mortal.game.view.levelReward.cellrender.*;
    import mortal.game.view.levelReward.other.*;

    public class LevelRewardVIPUpPanel extends ResBasePanel
    {
        private var panels:Vector.<Class>;
        private var currentIndex:int = -1;
        private var btnList:GTileList;
        private var currPanel:ResBasePanel;
        private var lastView:Boolean;

        public function LevelRewardVIPUpPanel()
        {
            this.panels = new Vector.<Class>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.bg(8, 0, 190, 528, this));
            pushUIToDisposeVec(UIFactory.bg(200, 0, 698, 528, this));
            this.btnList = UIFactory.tileList(10, 0, 185, 570, this);
            this.btnList.rowHeight = 71;
            this.btnList.columnWidth = 185;
            this.btnList.horizontalGap = 0;
            this.btnList.verticalGap = -3;
            this.btnList.columnCount = 1;
            this.btnList.rowCount = 6;
            this.btnList.setStyle("cellRenderer", LevelRewardVipUpBtnCellRenderer);
            this.btnList.verticalScrollPolicy = ScrollPolicy.OFF;
            this.lastView = false;
            this.refresh();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.btnList.dispose(param1);
            this.btnList = null;
            this.currPanel = null;
            this.currentIndex = -1;
            return;
        }// end function

        override public function refresh(param1:Boolean = false) : void
        {
            var _loc_4:LevelRewardVipUpBtnCellRenderer = null;
            super.refresh(param1);
            if (!allowRefresh)
            {
                return;
            }
            this.panels.length = 0;
            if (this.addLevelRewardVipUpGiftPanel())
            {
                this.panels.push(LevelRewardVipUpGiftPanel);
            }
            this.openPanel();
            this.btnList.dataProvider = this.getDataProvider();
            this.btnList.drawNow();
            var _loc_2:* = this.btnList.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                _loc_4 = this.btnList.itemToCellRenderer(this.btnList.getItemAt(_loc_3)) as LevelRewardVipUpBtnCellRenderer;
                _loc_4.btn.refresh(param1);
                _loc_3++;
            }
            if (this.currPanel)
            {
                this.currPanel.refresh(param1);
            }
            return;
        }// end function

        private function getDataProvider() : DataProvider
        {
            var _loc_4:LevelRewardVIPUpClickData = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = this.panels.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                _loc_4 = new LevelRewardVIPUpClickData();
                _loc_4.index = _loc_3;
                _loc_4.func = this.openPanel;
                _loc_4.pannel = this.panels[_loc_3];
                _loc_1.addItem(_loc_4);
                _loc_3++;
            }
            return _loc_1;
        }// end function

        private function openPanel(param1:LevelRewardVipUpBtn = null) : void
        {
            if (param1)
            {
                this.currentIndex = param1.index;
            }
            else
            {
                this.currentIndex = 0;
            }
            if (this.panels.length == 0)
            {
                return;
            }
            if (this.currPanel is this.panels[this.currentIndex])
            {
                return;
            }
            if (this.currPanel)
            {
                this.currPanel.dispose(false);
            }
            this.currPanel = UICompomentPool.getUICompoment(this.panels[this.currentIndex]);
            addChild(this.currPanel);
            return;
        }// end function

        public function get currentClass() : Class
        {
            return this.panels[this.currentIndex];
        }// end function

        private function addLevelRewardVipUpGiftPanel() : Boolean
        {
            var _loc_1:* = Cache.instance.levelReward.allLevelGiftsNum;
            var _loc_2:* = Cache.instance.levelReward.hasReceiveGiftsNum;
            var _loc_3:* = Cache.instance.levelReward.canReceiveGiftsNum;
            if (_loc_1 - _loc_2 == 1)
            {
                this.lastView = true;
            }
            if (_loc_1 == _loc_2)
            {
                this.lastView = false;
            }
            return true;
        }// end function

    }
}
